const {getCollectList} = require('../../utils/request');
const {article} = require('../../utils/config')
const {hitsCount} = require('../../utils/cloudRequest');

Page({


    data: {
        listLength: null,
        loading: null,
        articleList: []
    },

    onHandle(event) {
        const id = event.detail
        hitsCount(article, id).then()
        wx.navigateTo({
            url: `../articleDetail/index?id=${id}`,
        })
    },

    async onShow() {
        this.setData({
            loading: false
        })
        const openid = wx.getStorageSync('openid')
        //容器
        let container = [];
        await getCollectList('article', openid).then(res => {
            container = res.data
            this.setData({
                listLength: container.length
            })
        })
        for (let i = 0; i < this.data.listLength; i++) {
            let list = this.data.articleList
            list.push(container[i].detail)
            this.setData({
                articleList: list
            })
        }
        this.setData({
            loading: true
        })
    },

    onHide() {
        let list = []
        this.setData({
            articleList: list
        })
    },

})